#include <bits/stdc++.h>
using namespace std;

#define ONLINE_JUDGE

#ifndef ONLINE_JUDGE
#define dbg(x...)                             \
	{                                         \
		cerr << "\033[32;1m" << #x << " -> "; \
		err(x);                               \
	}
void err()
{
	cerr << "\033[39;0m" << endl;
}
template <typename T, typename... A>
void err(T a, A... x)
{
	cerr << a << ' ';
	err(x...);
}
#else
#define dbg(...)
#endif

typedef long long LL;

const int N = 1e3 + 50;
int n, a[N], s;

int maxSegment(int a[], int n)
{
	int res = 0, ans = 0;
	for (int i = 0; i < n; ++i)
	{
		// dbg(i, a[i]);
		res = max(0, res + a[i]);
		ans = max(ans, res);
	}
	return ans;
} 

vector<int> p[N];
int disc[N], dcnt;

int rnk[N];

int main(int argc, char const *argv[])
{
	int t;
	scanf("%d", &t);
	for (int kk = 1; kk <= t; ++kk)
	{
		scanf("%d%d", &n, &s);
		for (int i = 1; i <= n; ++i)
			scanf("%d", &a[i]);

		dcnt = 0;
		for (int i = 1; i <= n; ++i)
			disc[dcnt++] = a[i];
		sort(disc, disc + dcnt);
		dcnt = unique(disc, disc + dcnt) - disc;
		for (int i = 1; i <= n; ++i)
			a[i] = lower_bound(disc, disc + dcnt, a[i]) - disc + 1;
		for (int i = 1; i <= n; ++i)
		{
			p[i].clear();
		}
		for (int i = 1; i <= n; ++i)
		{
			rnk[i] = p[a[i]].size() + 1;
			p[a[i]].push_back(i);
		}

		int ans = 0;

		for (int st = 1; st <= n; ++st)
		{
			static int first[N], b[N];
			memset(first, 0, sizeof(int) * (n + 1));
			for (int j = st; j <= n; ++j)
			{
				b[j] = 1;
				if (first[a[j]] == 0)
				{
					first[a[j]] = rnk[j];
				}
				else if (rnk[j] - first[a[j]] == s)
					b[j] = -s;
				else if (rnk[j] - first[a[j]] > s)
					b[j] = 0;
				// dbg(j, rnk[j], first[a[j]]);
			}
			ans = max(ans, maxSegment(b + st, n - st + 1));
		}

		printf("Case #%d: %d\n", kk, ans);
		// return 0;
	}
	return 0;
}